package handler

type Node struct {
	path       string
	children   []*Node
	handleFunc HandleFunc
}

func (n *Node) createSubTrie(paths []string, handleFunc HandleFunc) {
	// var cur *Node 不要这么写
	cur := n
	for _, path := range paths {
		newNode := NewDefaultNode(path)
		n.children = append(n.children, newNode)
		cur = newNode
	}
	cur.handleFunc = handleFunc
}

func (n *Node) match(path string) (*Node, bool) {
	for _, child := range n.children {
		if child.path == path {
			return child, true
		}
	}
	return nil, false
}

func NewDefaultNode(path string) *Node {
	return NewNode(path, make([]*Node, 0, 2))
}

func NewNode(path string, children []*Node) *Node {
	return &Node{
		path:     path,
		children: children,
	}
}
